#include "NumGame.h"
#include <string>

USING_NS_CC;

bool TitleValue::init()
{
	if (!Sprite::init())
	{
		return false;
	}
	txtTitle = TextFieldTTF::create("", "Arial", 24);
	txtTitle->retain();
	txtValue = TextFieldTTF::create("", "Arial", 24);
	txtValue->retain();
	txtTitle->setTextColor(ccc4(0xFF, 0x99, 0x99, 0x99));
	txtValue->setTextColor(ccc4(0xFF, 0xDD, 0xDD, 0xDD));
	txtTitle->setPosition(0, 30);
	txtValue->setPosition(0, 5);
	addChild(txtTitle);
	addChild(txtValue);
	return true;
}

void TitleValue::setTitle(std::string title)
{
	txtTitle->setString(title);
}

void TitleValue::setValue(int value)
{
	String *s = String::createWithFormat("%d", value);
	txtValue->setString(s->_string);
	delete s;
}

TitleValue::~TitleValue()
{
	CC_SAFE_RELEASE_NULL(txtTitle);
	CC_SAFE_RELEASE_NULL(txtValue);
}

Scene* NumGame::createScene()
{
	auto scene = Scene::create();
	auto layer = NumGame::create();
	scene->addChild(layer);
	return scene;
}

bool NumGame::init()
{
	if (!LayerColor::initWithColor(ccc4(0xFF, 0x11, 0x11, 0x11)))
	{
		return false;
	}
	Size visibleSize = Director::getInstance()->getVisibleSize();
	Vec2 origin = Director::getInstance()->getVisibleOrigin();
	Vec2 center = origin + visibleSize * 0.5;
	TitleValue *score = TitleValue::create();
	TitleValue *best = TitleValue::create();
	score->setPosition(center.x - 50, center.y + 200);
	best->setPosition(center.x + 50, center.y + 200);
	addChild(score);
	addChild(best);
	score->setTitle("Score");
	score->setValue(0);
	best->setTitle("Best");
	best->setValue(0);
	return true;
}